package com.sinothk.server.support.entity;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {
    }

    //返回成功
    public static <T> Result<T> ok(T data, String msg) {
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.SUCCESS.code());
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        return ok(data, "操作成功");
    }

    public static <T> Result<T> ok() {
        return ok(null, "操作成功");
    }

    public static <T> Result<T> error(ResultCode resultCode) {
        Result<T> result = new Result<T>();
        result.setCode(resultCode.code());
        result.setMsg(resultCode.message());
        return result;
    }

    public static <T> Result<T> error(String msg) {
        return error(ResultCode.SYS_ERROR.code(), msg);
    }

    //返回失败
    public static <T> Result<T> error(Integer code, String msg) {
        Result<T> result = new Result<T>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
